package com.itheima;

import java.util.*;

/**
 * 演示collections工具类的使用
 */
public class CollectionsDemo {
    public static void main(String[] args) {
     //   extracted();
        test1();
    }

    private static void extracted() {
//       ArrayList<String> list = new ArrayList<>();
        //多态的写法
        List<String> list = new LinkedList<>();
        Collections.addAll(list, "zq", "zxy", "ysq","wangwu");
        list.forEach(System.out::println);
        System.out.println("-------------------");
        //打乱集合的顺序
        Collections.shuffle(list);
        list.forEach(System.out::println);
    }

    public  static void test1(){
        List<Integer> list = new LinkedList<>();
        Collections.addAll(list,1,2,3,4,5,6,7,8,9,10);
        //按照倒叙给序列排序
        Collections.sort(list);
        list.forEach(System.out::println);
//        Collections.sort(list, new Comparator<Integer>() {
//            @Override
//            public int compare(Integer o1, Integer o2) {
//                //安装倒序排
//                return o2-o1;
//            }
//        });
        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                //实现倒序排序
                return o2 - o1;
            }
        });
        System.out.println("--------------------------");
        list.forEach(System.out::println);

        //让学生Student实现Comparable接口，这样也能给学生排序
        System.out.println("-------------------");
        List<Student>list1 = new LinkedList<>();
        list1.add(new Student("赵六",20));
        list1.add(new Student("张三",25));
        list1.add(new Student("王五",23));
        Collections.sort(list1);
        list1.forEach(System.out::println);

       // List<Integer> synchronizedList = Collections.synchronizedList(list);
       // Collections.sort(synchronizedList);

    }
}